<?php

	$TEMP->set_file(array('handle' => DIR_IFRAME_VIEW . 'changePassword.html'));
	
	if ( isset($_POST['subButton']) ) {
		
		$if_error		= 0;
		$if_display		= 0;
		$txtusername	= _POST('txtusername');
		$txtoldpass		= _POST('txtoldpass', false);
		$txtnewpass		= _POST('txtnewpass', false); 
		$txtconfirmed	= _POST('txtconfirmed', false);
		
		if ( empty($txtusername) )	{ $if_error++; $_txtusername 	= WARNING_INPUT; }
		if ( empty($txtoldpass) )	{ $if_error++; $_txtoldpass 	= WARNING_INPUT; }
		else {
			$countRecord = $PI->getStudentOldPassword($txtoldpass);
			if ( $countRecord == 0 ) {
				$if_error++;
				$w_txtoldpass 	= OLD_CONFIRM;
			}
		}
		if ( empty($txtnewpass) )	{ $if_error++; $_txtnewpass 	= WARNING_INPUT; }
		else {
			if ( $txtnewpass != $txtconfirmed ) { $if_error++; $w_txtnewpass 	= PASS_CONFIRM; }
		}
		if ( empty($txtconfirmed) )	{ $if_error++; $_txtconfirmed 	= WARNING_INPUT; }
		
		if ( $if_error == 0 ) {
			
			$strArray = array('username' => $txtusername,
							  'password' => $txtnewpass);
			
			$PI->updateStudentPassword($strArray, $logUserID);
			$saved_record = "Saved";
			
		}
	}
	else {
		$txtusername = $PI->getStudentUsername($logUserID);
	}
	
	$TEMP->set_var(array('w_txtoldpass' 		=> $w_txtoldpass,
						 '_txtoldpass'			=> $_txtoldpass,
						 '_txtnewpass'			=> $_txtnewpass,
						 'w_txtnewpass'			=> $w_txtnewpass,
						 '_txtconfirmed'		=> $_txtconfirmed,
						 '_txtusername'			=> $_txtusername,
						 'txtusername'			=> $txtusername,
						 'saved_record'			=> $saved_record
						 ));
?>